package com.qjdchina.sku.biz.impl;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.qjdchina.commons.result.Result;
import com.qjdchina.sku.biz.UserRoleManager;
import com.qjdchina.sku.dao.mapper.UserRoleMapper;
import com.qjdchina.sku.model.UserRole;
import com.qjdchina.sku.service.enums.SkuResultCode;

/**
 * 用户角色关联
 * @author shenpingfeng
 * 2016年12月12日
 */
@Service
public class UserRoleManagerImpl implements UserRoleManager {

    public static final Logger LOGGER = LoggerFactory.getLogger(UserRoleManagerImpl.class);

    @Autowired
    private UserRoleMapper userRoleMapper ;

    /**
	 * 根据userId获取
	 * shenpingfeng
	 * 2016年12月12日
	 * @param userId
	 * @return
	 */
    @Override
    public Result<List<Integer>> findByUserId(Integer userId) {
    	if(userId == null){
    		return new Result<List<Integer>>(SkuResultCode.PARAMETER_NOT_EMPTY);
    	}
    	List<Integer> userRoles = userRoleMapper.selectByUserId(userId);
    	if(userRoles == null || userRoles.size() == 0){
    		return new Result<List<Integer>>(SkuResultCode.DATA_NOT_EXIST);
    	}
    	return new Result<List<Integer>>(userRoles);
     
    }
    
	/**
	 * 创建
	 * shenpingfeng
	 * 2017年1月13日
	 * @param userRole
	 * @return
	 */
    @Override
    public Result<String> create(UserRole userRole) {
    	if(userRole == null){
    		return new Result<String>(SkuResultCode.PARAMETER_NOT_EMPTY);
    	}
    	int row = userRoleMapper.insertSelective(userRole);
    	if(row == 0){
    		return new Result<String>(SkuResultCode.ADD_FAIL);
    	}
    	return new Result<String>(SkuResultCode.SUCCESS,"");
     
    }

   
}
